home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FAQ.SWG / 0023_Electronics Programming.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  5KB  |  154 lines

  1. {
  2. R C A Aldridge <RCA%IBM-B.RUTHERFORD.AC.UK@ib.rl.ac.uk>
  3.  
  4. +-------------------------------------+
  5. | Input / Output via the printer port |
  6. +-------------------------------------+
  7. +--------------------------+------------------------------+
  8. | By: Rafe Aldridge,       | E-Mail:                      |
  9. |     Street Farm,         | until July 1994:             |
  10. |     Dereham,             |  rca@ib.rl.ac.uk             |
  11. |     Garvestone,          |                              |
  12. |     Norfolk.             | Sept 1994 to July 1995:      |
  13. |     NR9 4QT              |  rcaldrid@genvax.glam.ac.uk  |
  14. |     England.             |                              |
  15. +--------------------------+------------------------------+
  16.  
  17. Intro:
  18. ------
  19. This document is intended for people with a good knowledge
  20. of electronics and programming. It covers the basics of
  21. getting TTL signals in and out of the IBM PC and compatibles
  22. via the parallel port.
  23.  
  24. Don't let the disclaimer section put you off. I have to say it
  25. to cover myself. Using the parallel port is a simple and fun way
  26. of interfacing your PC to the outside world.
  27.  
  28. Please feel free to mail me with any problems or queries.
  29. I will be glad to help.
  30.  
  31. ---------------------------------------------------------------------
  32.  
  33. When building items to connect to the parallel port follow
  34. these simple (and hopefully blindingly obvious) rules:
  35.   o Only use TTL levels with the parallel port.
  36.   o Always buffer signals.
  37.   o If you plan to interface mains with the PC:
  38.       - MAKE SURE YOU KNOW WHAT YOU'RE DOING
  39.       - always use mains rated isolators
  40.       - make sure mains cannot come in contact with the TTL
  41.       - ensure that things are adequatly earthed
  42.  
  43. ---------------------------------------------------------------------
  44. Disclaimer:
  45. -----------
  46. THIS IS ONLY A ROUGH GUIDE FOR PEOPLE WHO ARE EXPERIENCED
  47. IN PROGRAMMING AND ELECTRONICS. DUE TO THE WIDE RANGE OF
  48. ITEMS THAT COULD BE CONNECTED TO THE PORT NO WARRANTY IS
  49. OFFERED. RAFE ALDRIDGE IS NOT LIABLE UNDER ANY CIRCUMSTANCES
  50. FOR DAMAGE OR PROBLEMS ARISING AS A RESULT OF APPLYING
  51. ANY INFORMATION HERE.
  52.  
  53. ---------------------------------------------------------------------
  54. Programming:
  55. ------------
  56. Hopefully if I explain this first the following will make more sense.
  57.  
  58. The following examples show how to input and output data to and from
  59. the parallel port in Turbo Pascal 6+.
  60.  
  61. There are two ways of programming the parallel port.
  62.   1. Via the BIOS
  63.   2. Writing to the port directly.
  64.  
  65. 1:
  66. --
  67. This is the method I use and seems to work okay.
  68.  
  69. { get the status of the parallel port and return result in a byte }
  70. function input_from_parallel_port : byte; assembler;
  71. asm
  72.   mov ah,2 { bios service }
  73.   mov dx,0 { printer number; LPT1=0 LPT2=1 etc. }
  74.   int 17h  { interrupt }
  75. end;
  76.  
  77. { send the byte b to the parallel port }
  78. procedure output_to_parallel_port ( b : byte ); assembler;
  79. asm
  80.   mov ah,00  { bios service }
  81.   mov al,b
  82.   mov dx,0 { printer number; LPT1=0 LPT2=1 etc. }
  83.   int 17h  { interrupt }
  84. end;
  85.  
  86. {
  87. 2:
  88. --
  89. I personally have never done it this way. Don't even know if it will
  90. work or not! The basic idea is to use the port array to send or
  91. recieve a byte directly. I have used $387 as the address which is
  92. LPT1 on my machine.
  93.  
  94. { get the status of the parallel port and return result in a byte }
  95. function input_from_parallel_port : byte;
  96. begin
  97.   input_from_parallel_port:=port [$387];
  98. end;
  99.  
  100. { send the byte b to the parallel port }
  101. procedure output_to_parallel_port ( b : byte );
  102. begin
  103.   port [$387]:=b;
  104. end;
  105.  
  106. {
  107. Connector:
  108. ----------
  109. The parallel port on the PC is accessed via a 25 way female
  110. D type connector.
  111.  
  112. ---------------------------------------------------------------------
  113. Pins:
  114. -----
  115. There are 5 pins available for input and 8 for output.
  116.  
  117.  - input pins
  118.  
  119. | bit in AH | signal     | pin | state of bit when pin high
  120. +-----------+------------+-----+-----------------------------------
  121. |    7      | busy       |  11 | set to 1
  122. |    6      | -ack       |  10 | set to 0
  123. |    5      | paper out  |  12 | set to 1
  124. |    4      | select     |  13 | set to 1
  125. |    3      | -i/o error |  15 | set to 0
  126. |    2      | unused     |  -  |
  127. |    1      | unused     |  -  |
  128. |    0      | timeout    |  -  |
  129. +-----------+------------+-----+-----------------------------------
  130.  
  131. If things don't work as expected try tying pin 11 high (set printer
  132. not busy). Some PCs don't like the printer being busy. Sometimes
  133. this is made obvious by the timeout bit being set to 1 after a call
  134. to output_to_parallel_port (1) above.
  135.  
  136.  - output pins
  137.  
  138. | bit in AH | signal | pin
  139. +-----------+--------+-----
  140. |    7      | D7     |  9
  141. |    6      | D6     |  8
  142. |    5      | D5     |  7
  143. |    4      | D4     |  6
  144. |    3      | D3     |  5
  145. |    2      | D2     |  4
  146. |    1      | D1     |  3
  147. |    0      | D0     |  2
  148. +-----------+--------+-----
  149.  
  150. - ground pins
  151.  
  152. Pins 18-25 are ground pins. Connect all of these to the 0volt
  153. rail of the circuit under control.
  154.